/**
 * Created by dzd on 2017/3/24.
 */
(function () {
    'use strict';

    angular.module('App.pages.class')
        .controller('ClassNoticeCtrl', ClassNoticeCtrl);

    function ClassNoticeCtrl($state,$scope,ClassNoticeModel,AppUtils) {

        $scope.$on('$ionicView.beforeEnter', function (event, viewData) {
            viewData.enableBack = true;
        });

        $scope.gotoDetail = function(noticeId){
            if(!AppUtils.isUndefinedOrNull(noticeId)){
                $state.go("classMenu.noticeInfo",{noticeId:noticeId});
            }else{
                AppUtils.showAlert("请选择要查看的活动！");
            }
        }

        var vm = this;
        vm.exhortaions = [];
        vm.loadMoreBtnStatus = true;
        vm.loadMoreBtnStr = "加载更多";
        vm.pageIndex = 1;//第一页

        $scope.loadMoreNotice = function(){
            if(vm.loadMoreBtnStatus){
                vm.pageIndex = vm.pageIndex + 1;
                vm.getNoticePage();
            }
        }
        vm.getNoticePage = function(){
            ClassNoticeModel.getNoticePage({
                classId : 18,
                pageInfo: {
                    pageSize: 5,
                    pageNumber: vm.pageIndex
                }
            }).$promise.then(function(response){
                if(response.stat == 'err'){
                    AppUtils.showAlert(response.msg);
                }else{
                    var reponseDate = response.pageResult;
                    var items = reponseDate.pageResult;
                    var pageIndex = reponseDate.pageIndex;
                    var pageTotalPageSize = reponseDate.pageTotalPageSize;
                    if(pageIndex == pageTotalPageSize || items.length == 0){
                        vm.loadMoreBtnStatus = false;
                        vm.loadMoreBtnStr = "没有更多数据了";
                    }
                    angular.forEach(items,function(data){
                        vm.exhortaions.push(data);
                    })
                }
            })
        }
        vm.getNoticePage();
    }

})();
